<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/base.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
        .layui-form{
            width: 50%;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label ">菜单名</label>
        <div class="layui-input-block">
            <input type="hidden" name="id" id="userId" value="${requestScope.userInfo.id}">
            <input type="text" name="name"  placeholder="请输入用户名" value="${requestScope.userInfo.name}" class="layui-input">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        form.verify({
            idNumber:function(value){
                var result = null;
                var id = $("#userId").val();
                if(value!=null && value!=''){
                    //发送同步请求验证身份证号是否重复以及是否合法
                    $.ajax({
                        url:'checkIdNumber.ve',
                        type:'post',
                        data:{'idNumber':value, 'id':id},
                        dataType: 'json',
                        async:false,//同步
                        success:function (data){
                            if(data.code!=0){
                                result = data.msg;
                            }
                        }
                    });
                    if(result!=null){
                        return result;
                    }
                }
            },
            phone: function(value){
                if(value!=null && value!=''){
                    var phoneVerify = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                    if (!phoneVerify.test(value)){
                        return '手机号码格式不正确';
                    }
                }
            },
            email:function(value){
                var result = null;
                var id = $("#userId").val();
                if(value!=null && value!=''){
                    //验证email格式
                    var emailVerify = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                    if(!emailVerify.test(value)){
                        return '电子邮箱格式不正确';
                    }else{
                        //发送同步请求验证身份证号是否重复以及是否合法
                        $.ajax({
                            url:'${basePath}/checkEmail.ve',
                            type:'post',
                            data:{'email':value,'id':id},
                            dataType: 'json',
                            async:false,//同步
                            success:function (data){
                                if(data.code!=0){
                                    result = data.msg;
                                }
                            }
                        });
                        if(result!=null){
                            return result;
                        }
                    }

                }

            }
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url:'updateMenu.me',
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res){
                    if(res.code===0){
                            layer.msg(res.msg,function (){
                            parent.window.location.reload();
                        });
                    }else {
                        var index=layer.alert(res.msg,function (){
                            layer.close(index);
                        })
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>